using SM.core;
using SS;
using SS.dir;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace TVSBH.func
{
	public class frmListPrice : Form
	{
		private IContainer components = null;
		private DataGridView dgvProduct;
		private Button btnClose;
		private GroupBox groupBox1;
		private ComboBox cbbProduct;
		private Label label2;
		private ComboBox cbbParentGID;
		private Label label1;
		private CheckBox cbbAllProduct;
		private DataGridView dgvList1;
		private Button btnSave;
		private Button btnEdit;
		private Button btnAdd;
		private Button btnSearch;
		private DataGridViewTextBoxColumn DID;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
		private DataGridViewTextBoxColumn number;
		private DataGridViewTextBoxColumn productPrice1;
		private DataGridViewTextBoxColumn productPrice2;
		private DataGridViewTextBoxColumn Column10;
		private Label lblCurrProductName;
		private DataGridViewTextBoxColumn Column2;
		private DataGridViewTextBoxColumn Column1;
		private DataGridViewTextBoxColumn Column7;
		private DataGridViewTextBoxColumn Column8;
		private DataGridViewTextBoxColumn Column4;
		private DataGridViewTextBoxColumn Column5;
		private DataGridViewTextBoxColumn Column6;
		private DataGridViewTextBoxColumn Column3;
		private DataGridViewTextBoxColumn Column9;
		private DataGridViewTextBoxColumn Column11;
		private DataGridViewTextBoxColumn Column12;
		private Func objFunc = new Func();
		private DataTable objTable = new DataTable();
		private Bill objBill = new Bill();
		private string currWhID = "";
		public string userName = "";
		public string fullName = "";
		public string packet = "";
		public string currName = "";
		public int Pid = 0;
		private float curr_productPrice1 = 0f;
		private float curr_productPrice2 = 0f;
		private bool IsPostBack = false;
		private frmWaitting objW;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle6 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle7 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle8 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle9 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle10 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle11 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle12 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle13 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle14 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmListPrice));
			this.dgvProduct = new DataGridView();
			this.Column2 = new DataGridViewTextBoxColumn();
			this.Column1 = new DataGridViewTextBoxColumn();
			this.Column7 = new DataGridViewTextBoxColumn();
			this.Column8 = new DataGridViewTextBoxColumn();
			this.Column4 = new DataGridViewTextBoxColumn();
			this.Column5 = new DataGridViewTextBoxColumn();
			this.Column6 = new DataGridViewTextBoxColumn();
			this.Column3 = new DataGridViewTextBoxColumn();
			this.Column9 = new DataGridViewTextBoxColumn();
			this.Column11 = new DataGridViewTextBoxColumn();
			this.Column12 = new DataGridViewTextBoxColumn();
			this.btnClose = new Button();
			this.groupBox1 = new GroupBox();
			this.btnSearch = new Button();
			this.cbbAllProduct = new CheckBox();
			this.cbbProduct = new ComboBox();
			this.label2 = new Label();
			this.cbbParentGID = new ComboBox();
			this.label1 = new Label();
			this.dgvList1 = new DataGridView();
			this.DID = new DataGridViewTextBoxColumn();
			this.dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn();
			this.number = new DataGridViewTextBoxColumn();
			this.productPrice1 = new DataGridViewTextBoxColumn();
			this.productPrice2 = new DataGridViewTextBoxColumn();
			this.Column10 = new DataGridViewTextBoxColumn();
			this.btnSave = new Button();
			this.btnEdit = new Button();
			this.btnAdd = new Button();
			this.lblCurrProductName = new Label();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			this.groupBox1.SuspendLayout();
			((ISupportInitialize)this.dgvList1).BeginInit();
			base.SuspendLayout();
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToOrderColumns = true;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeight = 26;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Column2,
				this.Column1,
				this.Column7,
				this.Column8,
				this.Column4,
				this.Column5,
				this.Column6,
				this.Column3,
				this.Column9,
				this.Column11,
				this.Column12
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new System.Drawing.Point(7, 73);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			dataGridViewCellStyle2.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.RowsDefaultCellStyle = dataGridViewCellStyle2;
			this.dgvProduct.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(886, 304);
			this.dgvProduct.TabIndex = 1;
			this.dgvProduct.CellEnter += new DataGridViewCellEventHandler(this.dgvProduct_CellEnter);
			this.Column2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column2.DataPropertyName = "productName";
			this.Column2.HeaderText = "Sản phẩm";
			this.Column2.MinimumWidth = 100;
			this.Column2.Name = "Column2";
			this.Column2.ReadOnly = true;
			this.Column1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column1.DataPropertyName = "Packet";
			this.Column1.HeaderText = "Số lô";
			this.Column1.MinimumWidth = 120;
			this.Column1.Name = "Column1";
			this.Column1.ReadOnly = true;
			this.Column1.Width = 120;
			this.Column7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column7.DataPropertyName = "CreateDate";
			dataGridViewCellStyle3.Format = "D";
			dataGridViewCellStyle3.NullValue = null;
			this.Column7.DefaultCellStyle = dataGridViewCellStyle3;
			this.Column7.HeaderText = "Ngày nhập";
			this.Column7.MinimumWidth = 92;
			this.Column7.Name = "Column7";
			this.Column7.ReadOnly = true;
			this.Column7.Width = 92;
			this.Column8.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column8.DataPropertyName = "ProductExpiryDate";
			dataGridViewCellStyle4.Format = "D";
			dataGridViewCellStyle4.NullValue = null;
			this.Column8.DefaultCellStyle = dataGridViewCellStyle4;
			this.Column8.HeaderText = "Hạn dùng";
			this.Column8.MinimumWidth = 90;
			this.Column8.Name = "Column8";
			this.Column8.ReadOnly = true;
			this.Column8.Width = 90;
			this.Column4.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column4.DataPropertyName = "productNumber";
			dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle5.Format = "N0";
			dataGridViewCellStyle5.NullValue = null;
			this.Column4.DefaultCellStyle = dataGridViewCellStyle5;
			this.Column4.HeaderText = "Số lượng nhập";
			this.Column4.MinimumWidth = 120;
			this.Column4.Name = "Column4";
			this.Column4.ReadOnly = true;
			this.Column4.Width = 120;
			this.Column5.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column5.DataPropertyName = "ProductNumberOut";
			dataGridViewCellStyle6.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle6.Format = "N0";
			dataGridViewCellStyle6.NullValue = null;
			this.Column5.DefaultCellStyle = dataGridViewCellStyle6;
			this.Column5.HeaderText = "Số lượng xuất";
			this.Column5.MinimumWidth = 120;
			this.Column5.Name = "Column5";
			this.Column5.ReadOnly = true;
			this.Column5.Width = 120;
			this.Column6.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column6.DataPropertyName = "ProductNumberBalancer";
			dataGridViewCellStyle7.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle7.Format = "N0";
			dataGridViewCellStyle7.NullValue = null;
			this.Column6.DefaultCellStyle = dataGridViewCellStyle7;
			this.Column6.HeaderText = "Số lượng tồn";
			this.Column6.MinimumWidth = 120;
			this.Column6.Name = "Column6";
			this.Column6.ReadOnly = true;
			this.Column6.Width = 120;
			this.Column3.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column3.DataPropertyName = "productUnit";
			this.Column3.HeaderText = "Đơn vị tính";
			this.Column3.MinimumWidth = 110;
			this.Column3.Name = "Column3";
			this.Column3.ReadOnly = true;
			this.Column3.Width = 110;
			this.Column9.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column9.DataPropertyName = "Pid";
			this.Column9.HeaderText = "Mã sản phẩm";
			this.Column9.Name = "Column9";
			this.Column9.ReadOnly = true;
			this.Column9.Visible = false;
			this.Column11.DataPropertyName = "productPrice1";
			dataGridViewCellStyle8.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle8.Format = "N0";
			dataGridViewCellStyle8.NullValue = "0";
			this.Column11.DefaultCellStyle = dataGridViewCellStyle8;
			this.Column11.HeaderText = "Column11";
			this.Column11.Name = "Column11";
			this.Column11.ReadOnly = true;
			this.Column11.Visible = false;
			this.Column12.DataPropertyName = "productPrice2";
			dataGridViewCellStyle9.Format = "N0";
			dataGridViewCellStyle9.NullValue = "0";
			this.Column12.DefaultCellStyle = dataGridViewCellStyle9;
			this.Column12.HeaderText = "Column12";
			this.Column12.Name = "Column12";
			this.Column12.ReadOnly = true;
			this.Column12.Visible = false;
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new System.Drawing.Point(793, 566);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(100, 26);
			this.btnClose.TabIndex = 38;
			this.btnClose.Text = "Thoát  [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.groupBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox1.Controls.Add(this.btnSearch);
			this.groupBox1.Controls.Add(this.cbbAllProduct);
			this.groupBox1.Controls.Add(this.cbbProduct);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.cbbParentGID);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox1.Location = new System.Drawing.Point(7, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(886, 62);
			this.groupBox1.TabIndex = 39;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Điều kiện tìm kiếm";
			this.btnSearch.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.btnSearch.FlatAppearance.BorderColor = Color.Cyan;
			this.btnSearch.FlatStyle = FlatStyle.Flat;
			this.btnSearch.Location = new System.Drawing.Point(788, 26);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new Size(86, 23);
			this.btnSearch.TabIndex = 45;
			this.btnSearch.Text = "Hiển thị";
			this.btnSearch.UseVisualStyleBackColor = true;
			this.btnSearch.Click += new EventHandler(this.btnSearch_Click_1);
			this.cbbAllProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.cbbAllProduct.AutoSize = true;
			this.cbbAllProduct.Checked = true;
			this.cbbAllProduct.CheckState = CheckState.Checked;
			this.cbbAllProduct.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.cbbAllProduct.Location = new System.Drawing.Point(696, 28);
			this.cbbAllProduct.Name = "cbbAllProduct";
			this.cbbAllProduct.Size = new Size(89, 19);
			this.cbbAllProduct.TabIndex = 44;
			this.cbbAllProduct.Text = "Xem tất cả !";
			this.cbbAllProduct.UseVisualStyleBackColor = true;
			this.cbbAllProduct.CheckedChanged += new EventHandler(this.cbbAllProduct_CheckedChanged);
			this.cbbProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cbbProduct.BackColor = Color.White;
			this.cbbProduct.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbProduct.FlatStyle = FlatStyle.Flat;
			this.cbbProduct.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.cbbProduct.FormattingEnabled = true;
			this.cbbProduct.Location = new System.Drawing.Point(427, 25);
			this.cbbProduct.Name = "cbbProduct";
			this.cbbProduct.Size = new Size(263, 23);
			this.cbbProduct.TabIndex = 42;
			this.cbbProduct.SelectedIndexChanged += new EventHandler(this.cbbProduct_SelectedIndexChanged);
			this.cbbProduct.SelectedValueChanged += new EventHandler(this.cbbProduct_SelectedIndexChanged);
			this.label2.AutoSize = true;
			this.label2.BackColor = Color.White;
			this.label2.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label2.Location = new System.Drawing.Point(342, 28);
			this.label2.Name = "label2";
			this.label2.Size = new Size(69, 15);
			this.label2.TabIndex = 43;
			this.label2.Text = "Tên thuốc :";
			this.label2.TextAlign = ContentAlignment.MiddleRight;
			this.cbbParentGID.BackColor = Color.White;
			this.cbbParentGID.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbParentGID.FlatStyle = FlatStyle.Flat;
			this.cbbParentGID.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.cbbParentGID.FormattingEnabled = true;
			this.cbbParentGID.Location = new System.Drawing.Point(97, 24);
			this.cbbParentGID.Name = "cbbParentGID";
			this.cbbParentGID.Size = new Size(226, 23);
			this.cbbParentGID.TabIndex = 40;
			this.cbbParentGID.SelectedIndexChanged += new EventHandler(this.cbbParentGID_SelectedIndexChanged);
			this.cbbParentGID.SelectedValueChanged += new EventHandler(this.cbbParentGID_SelectedIndexChanged);
			this.label1.AutoSize = true;
			this.label1.BackColor = Color.White;
			this.label1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label1.Location = new System.Drawing.Point(20, 28);
			this.label1.Name = "label1";
			this.label1.Size = new Size(72, 15);
			this.label1.TabIndex = 41;
			this.label1.Text = "Loại thuốc :";
			this.label1.TextAlign = ContentAlignment.MiddleRight;
			this.dgvList1.AllowUserToAddRows = false;
			this.dgvList1.AllowUserToDeleteRows = false;
			this.dgvList1.AllowUserToResizeColumns = false;
			this.dgvList1.AllowUserToResizeRows = false;
			dataGridViewCellStyle10.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle10.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle10;
			this.dgvList1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvList1.BackgroundColor = Color.White;
			this.dgvList1.BorderStyle = BorderStyle.Fixed3D;
			this.dgvList1.ColumnHeadersHeight = 26;
			this.dgvList1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvList1.Columns.AddRange(new DataGridViewColumn[]
			{
				this.DID,
				this.dataGridViewTextBoxColumn1,
				this.number,
				this.productPrice1,
				this.productPrice2,
				this.Column10
			});
			this.dgvList1.EnableHeadersVisualStyles = false;
			this.dgvList1.Location = new System.Drawing.Point(7, 397);
			this.dgvList1.Name = "dgvList1";
			this.dgvList1.ReadOnly = true;
			this.dgvList1.RowHeadersVisible = false;
			dataGridViewCellStyle11.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList1.RowsDefaultCellStyle = dataGridViewCellStyle11;
			this.dgvList1.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList1.Size = new Size(886, 163);
			this.dgvList1.TabIndex = 40;
			this.DID.DataPropertyName = "UID";
			this.DID.HeaderText = "DID";
			this.DID.Name = "DID";
			this.DID.ReadOnly = true;
			this.DID.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.DID.Visible = false;
			this.dataGridViewTextBoxColumn1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.dataGridViewTextBoxColumn1.DataPropertyName = "UnitName";
			this.dataGridViewTextBoxColumn1.HeaderText = "Tên gọi";
			this.dataGridViewTextBoxColumn1.MinimumWidth = 250;
			this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
			this.dataGridViewTextBoxColumn1.ReadOnly = true;
			this.dataGridViewTextBoxColumn1.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dataGridViewTextBoxColumn1.Width = 250;
			this.number.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.number.DataPropertyName = "number";
			dataGridViewCellStyle12.Alignment = DataGridViewContentAlignment.MiddleRight;
			this.number.DefaultCellStyle = dataGridViewCellStyle12;
			this.number.HeaderText = "Quy đổi";
			this.number.MinimumWidth = 80;
			this.number.Name = "number";
			this.number.ReadOnly = true;
			this.number.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.number.Width = 80;
			this.productPrice1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productPrice1.DataPropertyName = "productPrice1";
			dataGridViewCellStyle13.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle13.Format = "N0";
			dataGridViewCellStyle13.NullValue = "0";
			this.productPrice1.DefaultCellStyle = dataGridViewCellStyle13;
			this.productPrice1.HeaderText = "Giá bán buôn";
			this.productPrice1.MinimumWidth = 90;
			this.productPrice1.Name = "productPrice1";
			this.productPrice1.ReadOnly = true;
			this.productPrice1.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productPrice1.Width = 90;
			this.productPrice2.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productPrice2.DataPropertyName = "productPrice2";
			dataGridViewCellStyle14.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle14.Format = "N0";
			dataGridViewCellStyle14.NullValue = "0";
			this.productPrice2.DefaultCellStyle = dataGridViewCellStyle14;
			this.productPrice2.HeaderText = "Giá bán lẻ";
			this.productPrice2.MinimumWidth = 90;
			this.productPrice2.Name = "productPrice2";
			this.productPrice2.ReadOnly = true;
			this.productPrice2.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productPrice2.Width = 90;
			this.Column10.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column10.HeaderText = "-:-";
			this.Column10.Name = "Column10";
			this.Column10.ReadOnly = true;
			this.Column10.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.btnSave.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnSave.Enabled = false;
			this.btnSave.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnSave.FlatStyle = FlatStyle.Flat;
			this.btnSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSave.Location = new System.Drawing.Point(191, 566);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new Size(90, 26);
			this.btnSave.TabIndex = 43;
			this.btnSave.Text = "Ghi nhận";
			this.btnSave.UseVisualStyleBackColor = true;
			this.btnSave.Click += new EventHandler(this.btnSave_Click);
			this.btnEdit.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnEdit.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnEdit.FlatStyle = FlatStyle.Flat;
			this.btnEdit.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnEdit.Location = new System.Drawing.Point(99, 566);
			this.btnEdit.Name = "btnEdit";
			this.btnEdit.Size = new Size(90, 26);
			this.btnEdit.TabIndex = 42;
			this.btnEdit.Text = "Cập nhật";
			this.btnEdit.UseVisualStyleBackColor = true;
			this.btnEdit.Click += new EventHandler(this.btnEdit_Click);
			this.btnAdd.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnAdd.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnAdd.FlatStyle = FlatStyle.Flat;
			this.btnAdd.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnAdd.Location = new System.Drawing.Point(7, 566);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new Size(90, 26);
			this.btnAdd.TabIndex = 41;
			this.btnAdd.Text = "Thêm mới";
			this.btnAdd.UseVisualStyleBackColor = true;
			this.btnAdd.Click += new EventHandler(this.btnAdd_Click);
			this.lblCurrProductName.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.lblCurrProductName.BackColor = SystemColors.ControlLight;
			this.lblCurrProductName.Location = new System.Drawing.Point(7, 380);
			this.lblCurrProductName.Name = "lblCurrProductName";
			this.lblCurrProductName.Size = new Size(886, 18);
			this.lblCurrProductName.TabIndex = 44;
			this.lblCurrProductName.Text = "-:-";
			this.lblCurrProductName.TextAlign = ContentAlignment.MiddleLeft;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.lblCurrProductName);
			base.Controls.Add(this.btnSave);
			base.Controls.Add(this.btnEdit);
			base.Controls.Add(this.btnAdd);
			base.Controls.Add(this.dgvList1);
			base.Controls.Add(this.groupBox1);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.dgvProduct);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.Name = "frmListPrice";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "QUẢN LÝ GIÁ";
			base.WindowState = FormWindowState.Maximized;
			base.Load += new EventHandler(this.frmInput_Load);
			base.KeyDown += new KeyEventHandler(this.frmInput_KeyDown);
			((ISupportInitialize)this.dgvProduct).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			((ISupportInitialize)this.dgvList1).EndInit();
			base.ResumeLayout(false);
		}
		public frmListPrice()
		{
			Program.strConnectionString = this.objFunc.strConnectionString;
			this.InitializeComponent();
		}
		private void frmInput_Load(object sender, EventArgs e)
		{
			this.currWhID = this.objFunc.getWarehouse(this.userName);
			this.objFunc.LoadComboBoxGProduct("SELECT GpID, UPPER(GpName) AS GpName FROM TabGproducts", this.cbbParentGID, "GpID", "GpName");
			this.dgvProduct.AutoGenerateColumns = false;
			this.getDetailBalancer("");
			this.IsPostBack = true;
			this.dataGridViewTextBoxColumn1.Width = this.Column2.Width - 18;
			this.number.Width = this.Column1.Width;
			this.productPrice1.Width = this.Column7.Width;
			this.productPrice2.Width = this.Column8.Width;
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmInput_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}
		private void btnPrint_Click(object sender, EventArgs e)
		{
		}
		private void cbbParentGID_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cbbParentGID.SelectedValue.ToString() != "0")
			{
				this.objFunc.LoadComboBox("SELECT PID, UPPER(P_Name) AS P_Name FROM [TabProducts] WHERE [GpID] = " + this.cbbParentGID.SelectedValue.ToString(), this.cbbProduct, "PID", "P_Name");
			}
			else
			{
				this.getDetailBalancer("");
			}
		}
		public void getDetailBalancer(string sqlQuery)
		{
			ThreadStart start = new ThreadStart(this.showWatting);
			Thread thread = new Thread(start);
			thread.Start();
			if (!thread.Join(150))
			{
				try
				{
					DataTable dataTable = new DataTable();
					DataColumn column = new DataColumn("Pid", typeof(string));
					DataColumn column2 = new DataColumn("ProductName", typeof(string));
					DataColumn column3 = new DataColumn("Packet", typeof(string));
					DataColumn column4 = new DataColumn("CreateDate", typeof(DateTime));
					DataColumn column5 = new DataColumn("ProductExpiryDate", typeof(DateTime));
					DataColumn column6 = new DataColumn("ProductNumber", typeof(string));
					DataColumn column7 = new DataColumn("ProductNumberOut", typeof(string));
					DataColumn column8 = new DataColumn("ProductNumberBalancer", typeof(string));
					DataColumn column9 = new DataColumn("ProductUnit", typeof(string));
					DataColumn column10 = new DataColumn("productPrice1", typeof(float));
					DataColumn column11 = new DataColumn("productPrice2", typeof(float));
					dataTable.Columns.Add(column);
					dataTable.Columns.Add(column2);
					dataTable.Columns.Add(column3);
					dataTable.Columns.Add(column4);
					dataTable.Columns.Add(column5);
					dataTable.Columns.Add(column6);
					dataTable.Columns.Add(column7);
					dataTable.Columns.Add(column8);
					dataTable.Columns.Add(column9);
					dataTable.Columns.Add(column10);
					dataTable.Columns.Add(column11);
					SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
					sqlConnection.Open();
					SqlCommand sqlCommand = sqlConnection.CreateCommand();
					if (sqlQuery == "")
					{
						sqlCommand.CommandText = "SELECT * FROM [TabDetailBill],[TabBill] WHERE [TabBill].[WID] = '" + this.currWhID + "' AND [TabDetailBill].[billID] = [TabBill].[ID] AND [TypeInput] IN ('IN1','IN2','IN3') ORDER BY [ProductName]";
					}
					else
					{
						sqlCommand.CommandText = sqlQuery;
					}
					SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
					while (sqlDataReader.Read())
					{
						float num = float.Parse(this.numInput(sqlDataReader["Pid"].ToString(), sqlDataReader["Packet"].ToString()));
						float num2 = float.Parse(this.numOutput(sqlDataReader["Pid"].ToString(), sqlDataReader["Packet"].ToString()));
						float num3 = num - num2;
						if (!this.checkProductNameInDataGridView(sqlDataReader["ProductName"].ToString(), sqlDataReader["Packet"].ToString(), dataTable))
						{
							if (!this.checkProductNameInDataGridView(sqlDataReader["ProductName"].ToString(), dataTable))
							{
								dataTable.Rows.Add(new object[]
								{
									sqlDataReader["Pid"].ToString(),
									sqlDataReader["ProductName"].ToString(),
									sqlDataReader["Packet"].ToString(),
									sqlDataReader["CreateDate"].ToString().Substring(0, 10),
									sqlDataReader["ProductExpiryDate"].ToString().Substring(0, 10),
									num.ToString(),
									num2.ToString(),
									num3.ToString(),
									" " + sqlDataReader["ProductUnit"].ToString(),
									float.Parse(sqlDataReader["productPrice1"].ToString()),
									float.Parse(sqlDataReader["productPrice2"].ToString())
								});
							}
							else
							{
								dataTable.Rows.Add(new object[]
								{
									sqlDataReader["Pid"].ToString(),
									"",
									sqlDataReader["Packet"].ToString(),
									sqlDataReader["CreateDate"].ToString().Substring(0, 10),
									sqlDataReader["ProductExpiryDate"].ToString().Substring(0, 10),
									num.ToString(),
									num2.ToString(),
									num3.ToString(),
									" " + sqlDataReader["ProductUnit"].ToString(),
									float.Parse(sqlDataReader["productPrice1"].ToString()),
									float.Parse(sqlDataReader["productPrice2"].ToString())
								});
							}
						}
					}
					sqlDataReader.Close();
					sqlConnection.Close();
					sqlConnection.Dispose();
					this.objTable = dataTable;
					this.dgvProduct.DataSource = this.objTable;
				}
				catch
				{
					this.objTable = null;
					this.dgvProduct.DataSource = this.objTable;
				}
			}
			thread.Abort();
		}
		private void showWatting()
		{
			this.objW = new frmWaitting();
			this.objW.ShowDialog();
			Thread.Sleep(40);
		}
		private bool checkProductNameInDataGridView(string pName, string Packet, DataTable objTable)
		{
			bool result = false;
			for (int i = 0; i < objTable.Rows.Count; i++)
			{
				if (objTable.Rows[i]["ProductName"].ToString().ToUpper() == pName.ToUpper() && objTable.Rows[i]["Packet"].ToString().ToUpper() == Packet.ToUpper())
				{
					result = true;
				}
			}
			return result;
		}
		private bool checkProductNameInDataGridView(string pName, DataTable objTable)
		{
			bool result = false;
			for (int i = 0; i < objTable.Rows.Count; i++)
			{
				if (objTable.Rows[i]["ProductName"].ToString().ToUpper() == pName.ToUpper())
				{
					result = true;
				}
			}
			return result;
		}
		private string numInput(string PID, string Packet)
		{
			string text = "0";
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = string.Concat(new string[]
			{
				"SELECT ISNULL((SELECT SUM(productNumber) FROM TabDetailBill WHERE BillID IN (SELECT ID FROM TabBill WHERE [WID] = '",
				this.currWhID,
				"' AND [TypeInput] IN ('IN1','IN2','IN3')) AND [PID] = ",
				PID,
				" AND packet = '",
				Packet,
				"'),0) AS numberInput"
			});
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["numberInput"].ToString();
				}
			}
			else
			{
				text = "0";
			}
			sqlDataReader.Close();
			sqlConnection.Close();
			sqlConnection.Dispose();
			if (text.Trim() == "")
			{
				text = "0";
			}
			return text;
		}
		private string numOutput(string PID, string Packet)
		{
			string text = "0";
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			sqlCommand.CommandText = string.Concat(new string[]
			{
				"SELECT ISNULL((SELECT SUM(productNumber/Rate) FROM TabDetailBill WHERE BillID IN (SELECT ID FROM TabBill WHERE [WID] = '",
				this.currWhID,
				"' AND [TypeInput] IN ('OUT1','OUT2','OUT3','OUT4')) AND [PID] = ",
				PID,
				" AND packet = '",
				Packet,
				"'),0) - ISNULL((SELECT SUM(productNumber) FROM TabDetailBill WHERE BillID IN (SELECT ID FROM TabBill WHERE [WID] = '",
				this.currWhID,
				"' AND [TypeInput] IN ('IN3')) AND [PID] = ",
				PID,
				" AND packet = '",
				Packet,
				"'),0) AS numberOut"
			});
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			if (sqlDataReader.HasRows)
			{
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["numberOut"].ToString();
				}
			}
			else
			{
				text = "0";
			}
			sqlDataReader.Close();
			sqlConnection.Close();
			sqlConnection.Dispose();
			if (text.Trim() == "")
			{
				text = "0";
			}
			return text;
		}
		private void btnSearch_Click(object sender, EventArgs e)
		{
			this.getDetailBalancer("");
		}
		private void cbbAllProduct_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbbAllProduct.Checked)
			{
				string sqlQuery = "SELECT * FROM [TabDetailBill],[TabBill] WHERE [TabDetailBill].[billID] = [TabBill].[ID] AND  [TypeInput] IN ('IN1','IN2','IN3') AND [TabDetailBill].[PID] IN (SELECT PID FROM [TabProducts] WHERE [GpID] = " + this.cbbParentGID.SelectedValue.ToString() + ") ORDER BY [ProductName]";
				this.getDetailBalancer(sqlQuery);
			}
			else
			{
				this.getDetailBalancer("");
			}
		}
		private void cbbProduct_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.IsPostBack)
			{
				string sqlQuery = "SELECT * FROM [TabDetailBill],[TabBill] WHERE [TabDetailBill].[billID] = [TabBill].[ID] AND  [TypeInput] IN ('IN1','IN2','IN3') AND [TabDetailBill].[PID] = " + this.cbbProduct.SelectedValue.ToString() + " ORDER BY [ProductName]";
				this.getDetailBalancer(sqlQuery);
			}
		}
		private void resetDataGridView()
		{
			this.objTable = null;
			this.dgvProduct.DataSource = this.objTable;
		}
		private void btnPrint_Click_1(object sender, EventArgs e)
		{
			frmRepBalancer.objTable = new DataTable();
			frmBalancerView frmBalancerView = new frmBalancerView();
			if (!this.cbbAllProduct.Checked)
			{
				frmBalancerView.productName = "Tên hàng hoá : " + this.cbbProduct.Text;
			}
			else
			{
				frmBalancerView.productName = "Tên hàng hoá : Tất cả";
			}
			frmBalancerView.productName = "Tên hàng hoá : Tất cả";
			frmBalancerView.productGroup = "Nhóm hàng hoá : Tất cả";
			frmRepBalancer.objTable = this.objTable;
			frmBalancerView.ShowDialog();
		}
		private void btnAdd_Click(object sender, EventArgs e)
		{
			try
			{
				if (this.currName != "")
				{
					SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
					sqlConnection.Open();
					string cmdText = "SELECT [uID], [UnitName], [number] FROM [TabProductUnitList] WHERE [Pid] = " + this.Pid;
					SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection);
					SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
					while (sqlDataReader.Read())
					{
						this.AddUnitList(this.Pid, int.Parse(sqlDataReader["uID"].ToString()), sqlDataReader["UnitName"].ToString(), int.Parse(sqlDataReader["number"].ToString()), this.packet, this.curr_productPrice1 / float.Parse(sqlDataReader["number"].ToString()), this.curr_productPrice2 / float.Parse(sqlDataReader["number"].ToString()));
					}
					sqlDataReader.Close();
					sqlConnection.Close();
					sqlConnection.Dispose();
					this.getListPrice();
				}
				else
				{
					MessageBox.Show("Không thể bổ sung giá cho đơn vị con của một sản phẩm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		public void AddUnitList(int Pid, int Uid, string UnitName, int number, string packet, float productPrice1, float productPrice2)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand(string.Concat(new object[]
				{
					"IF NOT EXISTS (SELECT * FROM [TabPacketPrice] WHERE [Pid] = ",
					this.Pid,
					" AND [Packet] = '",
					packet,
					"' AND [uID] = ",
					Uid.ToString(),
					") BEGIN INSERT INTO [TabPacketPrice] VALUES(",
					this.Pid,
					",",
					Uid,
					",N'",
					UnitName,
					"',",
					number,
					",'",
					packet,
					"',",
					productPrice1,
					",",
					productPrice2,
					") END ELSE UPDATE [TabPacketPrice] SET [productPrice1] = ",
					productPrice1,
					", productPrice2 = ",
					productPrice2,
					", [number] = ",
					number,
					" WHERE [Pid] = ",
					Pid,
					" AND [Packet] = '",
					packet,
					"' AND [uid] = ",
					Uid
				}), sqlConnection);
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		private void dgvProduct_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.Pid = int.Parse(this.dgvProduct.Rows[e.RowIndex].Cells["Column9"].Value.ToString());
				this.packet = this.dgvProduct.Rows[e.RowIndex].Cells["Column1"].Value.ToString();
				this.currName = this.dgvProduct.Rows[e.RowIndex].Cells["Column2"].Value.ToString();
				this.curr_productPrice1 = float.Parse(this.dgvProduct.Rows[e.RowIndex].Cells["Column11"].Value.ToString());
				this.curr_productPrice2 = float.Parse(this.dgvProduct.Rows[e.RowIndex].Cells["Column12"].Value.ToString());
				this.lblCurrProductName.Text = "Hệ thống đơn vị tính và giá tương ứng của : " + this.currName;
				this.getListPrice();
			}
			catch
			{
			}
		}
		private void getListPrice()
		{
			this.dgvList1.AutoGenerateColumns = false;
			this.dgvList1.DataSource = null;
			this.dgvList1.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			string cmdText = string.Concat(new object[]
			{
				"SELECT * FROM [TabPacketPrice] WHERE [Pid] = ",
				this.Pid,
				" AND [packet] = '",
				this.packet,
				"'"
			});
			SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
			DataSet dataSet = new DataSet();
			sqlConnection.Open();
			sqlDataAdapter.Fill(dataSet);
			this.dgvList1.DataSource = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
			sqlDataAdapter.Dispose();
			dataSet.Dispose();
		}
		private void btnSearch_Click_1(object sender, EventArgs e)
		{
			this.getDetailBalancer("");
		}
		private void btnEdit_Click(object sender, EventArgs e)
		{
			this.btnSave.Enabled = true;
			this.btnEdit.Enabled = false;
			this.dgvList1.ReadOnly = false;
		}
		private void btnSave_Click(object sender, EventArgs e)
		{
			try
			{
				for (int i = 0; i < this.dgvList1.RowCount; i++)
				{
					this.updatePrice(this.Pid, this.packet, this.dgvList1.Rows[i].Cells["productPrice1"].Value.ToString(), this.dgvList1.Rows[i].Cells["productPrice2"].Value.ToString(), this.dgvList1.Rows[i].Cells["DID"].Value.ToString());
				}
				this.btnSave.Enabled = false;
				this.btnEdit.Enabled = true;
				this.dgvList1.ReadOnly = true;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		public void updatePrice(int Pid, string packet, string P1, string P2, string uid)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand(string.Concat(new object[]
				{
					"UPDATE [TabPacketPrice] SET [productPrice1] = ",
					P1,
					",[productPrice2] =  ",
					P2,
					" WHERE [Pid] = ",
					Pid,
					" AND [uID] = ",
					uid,
					" AND [packet] = '",
					packet,
					"'"
				}), sqlConnection);
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
	}
}
